package com.twu.biblioteca.Models;

/**
 * Created by ubuntu on 4/30/14.
 */
public class Item {

    Item(String title) {
        this.title = title;
        available = true;
    }

    private String title;
    private boolean available;
    private User borrower;


    public String getTitle() {
    return title;
}

    public boolean isAvailable() {
        return available;
    }

    public boolean borrow(User currentUser)
    {
        if(isAvailable())
        {
            available = false;
            borrower = currentUser;
            return true;
        }
        return false;
    }


    public String getBorrowerId() {
        if(borrower!=null)
            return borrower.getUserName();
        return null;
    }

    public boolean returnItem(){
        if(!isAvailable()) {
            available = true;
            borrower=null;
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return title;
    }
}
